<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>{$school['title']}</title>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width initial-scale=1.0 maximum-scale=1.0 user-scalable=yes" />
<link type="text/css" rel="stylesheet" href="{OSSURL}public/mobile/css/bindingFormFor.css" />
<link type="text/css" rel="stylesheet" href="{OSSURL}public/mobile/css/greenStyle.css?v=4.60120" />
<script type="text/javascript" src="{MODULE_URL}public/mobile/js/jquery-1.11.3.min.js?v=4.6"></script>
<script src="{MODULE_URL}public/mobile/js/jquery.js"></script>
<script src="{OSSURL}public/mobile/js/PromptBoxUtil.js"></script>
{php include $this->template('port');}
</head>
<body>
<div class="all">
<div class="header mainColor">
	<div class="l"><a class="backOff" style="background:url({OSSURL}public/mobile/img/ic_arrow_left_48px_white.svg) no-repeat;background-size: 55% 55%;background-position: 50%;" href="javascript:history.go(-1);"></a></div>
	<div class="m">
		<span>账号绑定</span>
	</div>
</div>
<div class="_header"></div>
		<div class="bangdingForm">
			<div class="bangdingTab">
				<div class="changeTab leftPosition activeTab" onclick="changeTab(this,'parent');">我是家长</div>
				<div class="changeTab rightPosition" onclick="changeTab(this,'teacher');">我是老师</div>
			</div>
			<div class="bangdingBox">
				<div class="headerBox">
					<div class="leftHeader">
						<img id="wxiconpath" alt="" src="{php echo tomedia($_W['fans']['tag']['avatar']);}" />
						<span id="wxname">{$_W['fans']['nickname']}</span>
					</div>
					<div class="linkImg">
						<img alt="" src="{OSSURL}public/mobile/img/ico_linkImg.png" />
					</div>
					<div class="rightHeader">
						<img style="height:80px;" src="{OSSURL}public/mobile/img/default_babyHeader.png" />
						<span>学生</span>
					</div>
				</div>
				<div id="parentBox" class="changeBox activeBox">
					<ul>
						<li>
							<span class="l">学生姓名：</span>
							<span class="r">
								<input id="s_name" type="text" value="" />
							</span>
						</li>
						<li>
							<span class="l">手机号码：</span>
							<span class="r">
								<input id="mobile" type="tel" maxlength="11" value="" />
							</span>
						</li>
						<li>
							<span class="l">关&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;系：</span>
							<span class="r">
								<label>请选择</label>
									<select id="subjectId">
										<option value="">请选择</option>
										<option value="2">母亲</option>
										<option value="3">父亲</option>
										<option value="4">本人</option>
										<option value="5">家长</option>
									</select>
								<i></i>
							</span>
						</li>						
						<li class="no_padding">
							<span class="l"></span>
							<span class="remind">
								<i><img alt="" src="{OSSURL}public/mobile/img/ico_attention.png" /></i>
								<label>请输入报名时预留的手机号，一次绑定一个学生</label>
							</span>
						</li>
					</ul>
					<div class="submitBtn mainColor" onclick="bangDing();">绑定</div>
				</div>
				<div id="teacherBox" class="changeBox">
					<ul>
						<li>
							<span class="l">老师姓名：</span>
							<span class="r">
								<input id="tname" type="text" value="" />
							</span>
						</li>
						<li>
							<span class="l">绑定码：</span>
							<span class="r">
								<input id="tmobile" type="tel" value="" />
							</span>
						</li>
					</ul>
					<div class="submitBtn mainColor" onclick="bangDing1();">绑定</div>
				</div>
				
			</div>
			
		</div>
	</div>
</body>
<script type="text/javascript">
var PB = new PromptBox();
var campus = $("#campus").val();
var subjectId = $('#subjectId').val();
$(document).ready(function() {
	$("#subjectId").change(function() {
		changeGx();
	});
});
function changeGx(){
	$("#subjectId").parent().find("label").html($("#subjectId").find("option:selected").text());
}
function changeTab(obj,tabName){
	$(obj).parent().children().removeClass("activeTab");
	$(obj).addClass("activeTab");
	$("#"+tabName+"Box").parent().find(".changeBox").removeClass("activeBox");
	$("#"+tabName+"Box").addClass("activeBox");
	var bangdingStr = "";
	var imgSrc = "";
	if(tabName == "parent"){
		bangdingStr = "我的孩子";
		imgSrc = "../addons/fm_jiaoyu/public/mobile/img/default_babyHeader.png";
	}else if(tabName == "teacher"){
		bangdingStr = "我的校园";
		imgSrc = "../addons/fm_jiaoyu/public/mobile/img/default_school.png";
	}else{
		bangdingStr = "未知绑定";
	}
	$(".rightHeader").find("span").html(bangdingStr);
	$(".rightHeader").find("img").attr("src",imgSrc);
}

function bangDing(){
	var activeBoxID = $(".bangdingBox").find(".activeBox").attr("id");
	if(activeBoxID == "parentBox"){
		if($("#s_name").val() == null || $("#s_name").val() == ""){
			PB.prompt("学生姓名不能为空！");
			return;
		}else if($("#subjectId").val() == null || $("#subjectId").val() == ""){
			PB.prompt("请选择关系！");
			return;
		}else if($("#mobile").val() == null || $("#mobile").val() == ""){
			PB.prompt("手机号码不能为空！");
			return;
		}else if(!$("#mobile").val().match(/^(0|86|17951)?(13[0-9]|15[012356789]|17[0-9]|18[0-9]|14[57])[0-9]{8}$/)){
			PB.prompt("手机格式不正确！");
			return;
		}
	}
	jConfirm("确认绑定？", "删除确定对话框", function (isConfirm) {
		if(isConfirm){
			var submitData = {
				openid :"{$openid}",
				schoolid :"{$schoolid}",
				weid :"{$weid}",
				uid :"{$fan['uid']}",
				s_name : $("#s_name").val(),
				subjectId : $("#subjectId").val(),  //关系
				mobile : $("#mobile").val(),
			};
				$.post("{php echo $this->createMobileUrl('indexajax',array('op'=>'bdxs'))}",submitData,function(data){
				if(data.result){
					PB.prompt(data.msg);
					window.location.href = "{php echo $this->createMobileUrl('user', array('schoolid' => $schoolid), true)}"
				}else{
					PB.prompt(data.msg);
				}
			},'json'); 
		}
	});
}

		
function bangDing1(){
	var activeBoxID = $(".bangdingBox").find(".activeBox").attr("id");
    if(activeBoxID == "teacherBox"){
		if($("#tname").val() == null || $("#tname").val() == ""){
			PB.prompt("老师姓名不能为空！");
			return;
		}else if($("#tmobile").val() == null || $("#tmobile").val() == ""){
			PB.prompt("绑定码不能为空！");
			return;
		}
	}
	jConfirm("确认绑定？", "删除确定对话框", function (isConfirm) {
		if(isConfirm){
			var submitData = {
				openid :"{$openid}",
				schoolid :"{$schoolid}",
				weid :"{$weid}",
				uid :"{$fan['uid']}",
				tname : $("#tname").val(),
				code : $("#tmobile").val(),
			};
			$.post("{php echo $this->createMobileUrl('indexajax', array('op' => 'bdls'))}",submitData,function(data){
						if(data.result){
							PB.prompt(data.msg);
							window.location.href = "{php echo $this->createMobileUrl('myschool', array('schoolid' => $schoolid), true)}"
						}else{
							PB.prompt(data.msg);
						}
			},'json');	
		} 
	}); 	
}
</script>
</html>